package com.apes.scm.masterdata.frame.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.frame.model.Channel;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface ChannelRepository  extends CustomRepository<Channel, String> {

    @Query("select new map(s.id as id, s.name as name, s.description as description, s.inner as inner, s.valid as valid, " +
            " s.updateDate as updateDate, to_char(s.lastUpdatedStamp, 'yyyy-mm-dd hh24:mi:ss.FF3') as lastUpdatedStamp )  " +
            " FROM Channel s " +
            " where s.lastUpdatedStamp > :times or (s.id > :id and s.lastUpdatedStamp = :times)  " +
            " order by s.lastUpdatedStamp, s.id asc ")
    List<Map> findChannelByTs(@Param("times") Date times, @Param("id") String id, Pageable pageable);
    @Query(value="SELECT T FROM Channel T WHERE T.type=true AND T.valid=true")
    List<String> findIdAllByType();
}
